package xlx.com.myapplication;


import android.app.Activity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import java.util.List;

import xlx.com.myapplication.adapter.MyAdapter;
import xlx.com.myapplication.bean.DataCallBack;

public class MainActivity extends Activity {
    private RecyclerView mRecyclerView;
    private RecyclerView.LayoutManager mLayoutManager;
    private MyAdapter mAdapter;
    private List<DataCallBack> stringList;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
        initRecyclerView();
    }

    public void initView() {
        Gson gson = new Gson();
        String str = "[{\"title\":\"笔记本\",\"info\":[{\"id\":100,\"info\":\"苹果\"},{\"id\":101,\"info\":\"惠普\"},{\"id\":102,\"info\":\"戴尔\"}]},{\"title\":\"手机\",\"info\":[{\"id\":100,\"info\":\"苹果\"},{\"id\":101,\"info\":\"华为9\"},{\"id\":101,\"info\":\"华为P6\"},{\"id\":101,\"info\":\"华为5\"},{\"id\":101,\"info\":\"华为P4\"},{\"id\":101,\"info\":\"华为P3\"},{\"id\":101,\"info\":\"华为p2\"},{\"id\":101,\"info\":\"华为\"},{\"id\":102,\"info\":\"联想\"}]},{\"title\":\"电视\",\"info\":[{\"id\":100,\"info\":\"三星\"},{\"id\":101,\"info\":\"索尼\"},{\"id\":102,\"info\":\"长虹\"},{\"id\":102,\"info\":\"创维\"}]},{\"title\":\"台式机\",\"info\":[{\"id\":100,\"info\":\"宏基\"},{\"id\":101,\"info\":\"联想87500\"},{\"id\":102,\"info\":\"E5eoo\"}]},{\"title\":\"红酒\",\"info\":[{\"id\":100,\"info\":\"张裕\"},{\"id\":101,\"info\":\"拉菲2005\"},{\"id\":102,\"info\":\"长城\"}]},{\"title\":\"白酒\",\"info\":[{\"id\":100,\"info\":\"五粮液\"},{\"id\":101,\"info\":\"茅台\"},{\"id\":102,\"info\":\"国1573\"}]},{\"title\":\"饮料\",\"info\":[{\"id\":100,\"info\":\"娃哈哈\"},{\"id\":101,\"info\":\"哈哈哈\"},{\"id\":102,\"info\":\"果汁\"}]},{\"title\":\"矿泉水\",\"info\":[{\"id\":100,\"info\":\"农夫山泉有点甜4\"},{\"id\":100,\"info\":\"农夫山泉有点甜3\"},{\"id\":100,\"info\":\"农夫山泉有点甜2\"},{\"id\":100,\"info\":\"农夫山泉有点甜1\"},{\"id\":100,\"info\":\"农夫山泉有点甜\"},{\"id\":101,\"info\":\"恒大冰泉\"},{\"id\":102,\"info\":\"碧绿\"}]},{\"title\":\"家具\",\"info\":[{\"id\":100,\"info\":\"家具1\"},{\"id\":101,\"info\":\"家具2\"},{\"id\":102,\"info\":\"家具3\"}]},{\"title\":\"矿泉水\",\"info\":[{\"id\":100,\"info\":\"农夫山泉\"},{\"id\":101,\"info\":\"怡宝\"},{\"id\":102,\"info\":\"苏打水\"}]},{\"title\":\"鼠标\",\"info\":[{\"id\":100,\"info\":\"雷瑟\"},{\"id\":101,\"info\":\"蝰蛇\"},{\"id\":102,\"info\":\"罗技\"},{\"id\":102,\"info\":\"大蛇\"}]},{\"title\":\"牙膏\",\"info\":[{\"id\":100,\"info\":\"黑人\"},{\"id\":101,\"info\":\"冷三菱\"},{\"id\":102,\"info\":\"中华\"}]},{\"title\":\"白酒\",\"info\":[{\"id\":100,\"info\":\"伏尔加\"},{\"id\":101,\"info\":\"larB\"},{\"id\":102,\"info\":\"窖藏\"}]},{\"title\":\"白酒\",\"info\":[{\"id\":100,\"info\":\"五粮液\"},{\"id\":101,\"info\":\"茅台\"},{\"id\":102,\"info\":\"国1573\"}]},{\"title\":\"饮料\",\"info\":[{\"id\":100,\"info\":\"娃哈哈\"},{\"id\":101,\"info\":\"哈哈哈\"},{\"id\":102,\"info\":\"果汁\"}]},{\"title\":\"矿泉水\",\"info\":[{\"id\":100,\"info\":\"农夫山泉有点甜\"},{\"id\":101,\"info\":\"恒大冰泉\"},{\"id\":102,\"info\":\"碧绿\"}]},{\"title\":\"家具\",\"info\":[{\"id\":100,\"info\":\"家具1\"},{\"id\":101,\"info\":\"家具2\"},{\"id\":102,\"info\":\"家具3\"}]},{\"title\":\"手机\",\"info\":[{\"id\":100,\"info\":\"苹果\"},{\"id\":101,\"info\":\"华为\"},{\"id\":102,\"info\":\"联想\"}]},{\"title\":\"电视\",\"info\":[{\"id\":100,\"info\":\"三星\"},{\"id\":101,\"info\":\"索尼\"},{\"id\":102,\"info\":\"长虹\"},{\"id\":102,\"info\":\"创维\"}]},{\"title\":\"台式机\",\"info\":[{\"id\":100,\"info\":\"宏基\"},{\"id\":101,\"info\":\"联想87500\"},{\"id\":102,\"info\":\"E5eoo\"}]},{\"title\":\"红酒\",\"info\":[{\"id\":100,\"info\":\"张裕\"},{\"id\":101,\"info\":\"拉菲2005\"},{\"id\":102,\"info\":\"长城\"}]},{\"title\":\"白酒\",\"info\":[{\"id\":100,\"info\":\"五粮液\"},{\"id\":101,\"info\":\"茅台\"},{\"id\":102,\"info\":\"国1573\"}]},{\"title\":\"饮料\",\"info\":[{\"id\":100,\"info\":\"娃哈哈\"},{\"id\":101,\"info\":\"哈哈哈\"},{\"id\":102,\"info\":\"果汁\"}]},{\"title\":\"矿泉水\",\"info\":[{\"id\":100,\"info\":\"农夫山泉有点甜\"},{\"id\":101,\"info\":\"恒大冰泉\"},{\"id\":102,\"info\":\"碧绿\"}]},{\"title\":\"家具\",\"info\":[{\"id\":100,\"info\":\"家具1\"},{\"id\":101,\"info\":\"家具2\"},{\"id\":102,\"info\":\"家具3\"}]}]";
        stringList = gson.fromJson(str, new TypeToken<List<DataCallBack>>() {
        }.getType());
        stringList.toString();
    }

    private void initRecyclerView() {
        //实例化RecyclerView
        mRecyclerView = (RecyclerView) findViewById(R.id.recyclerview);
        mLayoutManager = new LinearLayoutManager(this);
        //为RecyclerView创建布局管理器，这里使用的是LinearLayoutManager，表示里面的Item排列是线性排列
        mRecyclerView.setLayoutManager(mLayoutManager);
        mAdapter = new MyAdapter(this,stringList);
        //设置数据适配器
        mRecyclerView.setAdapter(mAdapter);
    }

}